﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Midapex.SmartOrm.Tools.Wizard
{
    public partial class SQLiteConnForm : Form
    {
        public SQLiteConnForm()
        {
            InitializeComponent();
        }

        internal string GetConnString()
        {
            string conn =  string.Format("Data Source={0}", tbDbFile.Text);
            if (cbEncrypt.Checked)
            {
                conn += string.Format(";Password={0}", tbPassword.Text);
            }

            return conn;
        }

        private void buttonOK_Click(object sender, EventArgs e)
        {
            if(string.IsNullOrEmpty(tbDbFile.Text))
            {
                MessageBox.Show("Please select a SQLite db file first");
                return;
            }
            if (cbEncrypt.Checked && string.IsNullOrEmpty(tbPassword.Text))
            {
                MessageBox.Show("Please input db file encrypt password");
                return;
            }

            this.DialogResult = DialogResult.OK;
        }

        private void buttonSelectFile_Click(object sender, EventArgs e)
        {
            if (saveFileDialog.ShowDialog() == DialogResult.OK)
            {
                this.tbDbFile.Text = saveFileDialog.FileName;
            }
        }

        private void cbEncrypt_CheckedChanged(object sender, EventArgs e)
        {
            if (cbEncrypt.Checked)
            {
                tbPassword.Enabled = true;
            }
            else
            {
                tbPassword.Enabled = false;
            }

        }
    }
}